//
//  ViewController.swift
//  LeakTest
//
//  Created by 李文全 on 2025/11/3.
//

import UIKit
import SnapKit
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "循环引用功能测试"
        setUI()
    }
    
    
    func setUI(){
        
        let leakBtn = UIButton(type: .custom)
        leakBtn.addTarget(self, action: #selector(leakAction), for: .touchUpInside)
        leakBtn.setTitle("block循环引用", for: .normal)
        leakBtn.backgroundColor = .red
        
        self.view.addSubview(leakBtn)
        leakBtn.snp.makeConstraints { make in
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(20) //距离上面的安全距离为20
            make.right.left.equalToSuperview().inset(20)
            make.height.equalTo(50)
        }
        
        
        let leakBtn1 = UIButton(type: .custom)
        leakBtn1.addTarget(self, action: #selector(leakAction1), for: .touchUpInside)
        leakBtn1.setTitle("delegate循环引用", for: .normal)
        leakBtn1.backgroundColor = .red
        
        self.view.addSubview(leakBtn1)
        leakBtn1.snp.makeConstraints { make in
            make.top.equalTo(leakBtn.snp.bottom).offset(20) //距离上面的安全距离为20
            make.right.left.equalToSuperview().inset(20)
            make.height.equalTo(50)
        }
        
        
        let leakBtn2 = UIButton(type: .custom)
        leakBtn2.addTarget(self, action: #selector(leakAction2), for: .touchUpInside)
        leakBtn2.setTitle("定时器循环引用", for: .normal)
        leakBtn2.backgroundColor = .red
        
        self.view.addSubview(leakBtn2)
        leakBtn2.snp.makeConstraints { make in
            make.top.equalTo(leakBtn1.snp.bottom).offset(20) //距离上面的安全距离为20
            make.right.left.equalToSuperview().inset(20)
            make.height.equalTo(50)
        }
        
        
    }
    
    
    @objc func leakAction(){
        print("bloc循环引用")
        navigationController?.pushViewController(BlockViewController(), animated: true)
    }
    
    
    @objc func leakAction1(){
        print("delegate循环引用")
        navigationController?.pushViewController(DelegateViewController(), animated: true)
    }
    
    
    @objc func leakAction2(){
        print("定时器循环引用")
        navigationController?.pushViewController(TimerViewController(), animated: true)
    }
    
    
    


}

